<?php
if( !isset($AppUI) || 
	!isset($_SESSION['category'])
) {
	redirect(HOST_BACKEND);
}
$intAction 		= $this->input->post('paction', 0);
$arrCategoryId 	= $this->input->post('pcategoryid', null);
$strError		= '';
$strMsg			= '';

if($intAction && $arrCategoryId) {
	$this->load->model('category_model', 'category');	
	switch ($intAction) {
		case 1: // active
			if(isset($_SESSION['category']) && ($_SESSION['category']&1<<5) != 0) {							
				foreach($arrCategoryId as $row) {
					$intError  = $this->category->updateStatus($AppUI->id,$row,1,1<<5);
				}
				$strMsg		= $arrMessage['category_update'];
			}
			else {
				$strError	= $arrError['noperm_category_update'];
			}
			break;
		case 2: // delete
			if(isset($_SESSION['category']) && ($_SESSION['category']&1<<3) != 0) {				
				foreach($arrCategoryId as $row) {
					$this->category->updateStatus($AppUI->id,$row,2,8);
				}
				$strMsg		= $arrMessage['category_delete'];
			}
			else {
				$strError	= $arrError['noperm_category_delete'];
			}
			break;
		case 3://suspend
			if(isset($_SESSION['category']) && ($_SESSION['category']&1<<4) != 0) {	
				foreach($arrCategoryId as $row) {
					$intError  = $this->category->updateStatus($AppUI->id,$row,0,1<<4);
				}
				$strMsg		= $arrMessage['category_update'];
			}
			else {
				$strError	= $arrError['noperm_category_update'];
			}
			
		case 4: // delete database
			if(isset($_SESSION['category']) && ($_SESSION['category']&1<<3) != 0 && $AppUI->type > 1) {
				foreach($arrCategoryId as $row) {
					$this->category->delete($AppUI->id,$row);
				}
				$strMsg		= $arrMessage['category_delete'];
			}
			else {
				$strError	= $arrError['noperm_category_delete'];
			}
			break;
		case 5:
			//reject
			if(isset($_SESSION['category']) && ($_SESSION['category']&1<<4) != 0) {	
				foreach($arrCategoryId as $row) {
					$intError  = $this->category->updateStatus($AppUI->id,$row,6,16);
				}
				$strMsg		= $arrMessage['category_update'];
			}
			else {
				$strError	= $arrError['noperm_category_update'];
			}
			break;
		
	}
} else {
	$strError	= $arrError['nodata_act'];
}
if($strError == '') {
	CI_Function::setMsg($strMsg);
} else {
	CI_Function::setError($strError);	
}
redirect(isset($_SESSION[SESSION_BACKURL]) ? $_SESSION[SESSION_BACKURL] : HOST_BACKEND);

